<template>
  <section class="component add-account">
    <data-box class="expression-base-data-box" :data="expressionDataSet">
      <template slot="columns">
        <el-table-column label="收款方式" prop="relation" :min-width="$helper.getColumnWidth(4)">
          <template slot-scope="scope">
            <el-select v-model="scope.row.paymentType" clearable>
              <el-option v-for="{name,code} of $dict.getDictData('PaymentType')" :key="code" :label="name" :value="code"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="收款账户" prop="receiveName" :min-width="$helper.getColumnWidth(6)">
          <template slot-scope="scope">
            <el-input v-model="scope.row.receiveName" placeholder="请输入收款账户" clearable></el-input>
          </template>
        </el-table-column>
        <el-table-column label="收款账号" prop="receiveCardNumber" :min-width="$helper.getColumnWidth(6)">
          <template slot-scope="scope">
            <el-input v-model="scope.row.receiveCardNumber" placeholder="请输入收款账号" clearable></el-input>
          </template>
        </el-table-column>
        <el-table-column label="收款开户行" prop="receiveBank" :min-width="$helper.getColumnWidth(7)">
          <template slot-scope="scope">
            <el-input v-model="scope.row.receiveBank" placeholder="请输入收款开户行" clearable></el-input>
          </template>
        </el-table-column>
        <el-table-column label="收款二维码" prop="fileList" :min-width="$helper.getColumnWidth(4)">
          <template slot-scope="scope">
            <flie-upload v-show="scope.row.fileList && !scope.row.fileList.length" :fileList.sync="scope.row.fileList" :AllowExtension="['jpg','png','jpeg']" :showFileList="false" :fileNumberLimit="1" :buttonType="'text'" :buttonName="'上传'" />

            <el-popover v-if="scope.row.fileList && scope.row.fileList.length" placement="top" width="160" @show="onClickShow(scope.row)">
              <img :src="imgUrl" alt="" style="width:158px">
              <el-button slot="reference" type="text">预览</el-button>
            </el-popover>

          </template>
        </el-table-column>
        <el-table-column label="操作" width="120px">
          <template slot-scope="scope">
            <el-button type="text" @click="deleteClick(scope)">删除</el-button>
          </template>
        </el-table-column>
      </template>
    </data-box>

  </section>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop, Model, Watch } from 'vue-property-decorator';
import DataBox from '~/components/common/data-box.vue'
import FlieUpload from '~/components/common/file-upload.vue'
import { PrincipalService } from "~/services/domain-service/principal.service";
import { Dependencies } from "~/core/decorator";

@Component({
  components: {
    DataBox,
    FlieUpload
  }
})
export default class AddAccount extends Vue {
  @Model('change') private expressionDataSet
  @Dependencies(PrincipalService)
  private principalService: PrincipalService;
  private relationData: any = []
  private show: boolean = false
  private imgUrl: string = ''


  private onClickShow(row) {
    this.imgUrl = row.fileList[0].response.url
  }

  private deleteClick(scope) {
    if (scope.row.id) {
      this.principalService.deleteReceivAccountById(scope.row.id).subscribe(
        data => {
          this.expressionDataSet.splice(scope.$index, 1)
        },
        ({ msg }) => { }
      );
    } else {
      this.expressionDataSet.splice(scope.$index, 1)
    }
  }
}

</script>
<style lang="less">
.add-account {
  width: 98%;
}
</style>